package com.meida.module.system.provider.service.impl;

import com.meida.common.constants.CommonConstants;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.system.client.entity.SysType;
import com.meida.module.system.provider.mapper.SysTypeMapper;
import com.meida.module.system.provider.service.SysTypeService;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 分类表 实现类
 *
 * @author flyme
 * @date 2019-11-16
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysTypeServiceImpl extends BaseServiceImpl<SysTypeMapper, SysType> implements SysTypeService {

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public List<EntityMap> listByGroupId(Long groupId) {
        CriteriaQuery<SysType> cq = new CriteriaQuery(SysType.class);
        cq.select(SysType.class, "typeId", "typeName", "typeLogo");
        cq.eq(true, "state", CommonConstants.ENABLED);
        cq.eq("groupId", groupId);
        cq.orderByAsc("sortOrder");
        return selectEntityMap(cq);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public List<EntityMap> listByTypeCode(String typeCode) {
        CriteriaQuery<SysType> cq = new CriteriaQuery(SysType.class);
        cq.select(SysType.class, "typeId", "typeName", "typeLogo");
        cq.eq(true, "state", CommonConstants.ENABLED);
        cq.eq("typeCode", typeCode);
        cq.orderByAsc("sortOrder");
        return selectEntityMap(cq);
    }
}
